package com.wcgksoft.mobileservice.Account.plant;


import com.wcgksoft.common.util.MsgInfo;
import com.wcgksoft.entity.Plant.PlantEncyclopedias;
import com.wcgksoft.service.plant.PlantEncyclopediasService;
import com.wcgksoft.service.plant.PlantService;
import com.wcgksoft.service.plant.PlantTypeService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 植物百科
 *
 * @author Administrator
 */
@Controller
@RequestMapping("mobile/plantencyclopedias")
public class AppPlantEncyclopediasController {

    @Autowired
    private PlantEncyclopediasService plantEncyclopediasService;
    @Autowired
    private PlantTypeService plantTypeService;
    @Autowired
    private PlantService plantService;

    /**
     * 列表
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "list")
    public MsgInfo list( @RequestParam(value = "enterpriseid", required = false) Integer enterpriseid,
                         @RequestParam(value = "curPage", defaultValue = "1", required = false) Integer curPage,
                         @RequestParam(value = "pageSize",defaultValue = "8", required = false) Integer pageSize) {
        MsgInfo msgInfo = new MsgInfo();
        DetachedCriteria criteria = DetachedCriteria.forClass(PlantEncyclopedias.class);
        criteria.add(Restrictions.eq("enterpriseid", enterpriseid));
        List<PlantEncyclopedias> list = plantEncyclopediasService.findByConditions(criteria,curPage-1,pageSize);
        if(list.size()>0){
            msgInfo.setCode((int) Math.ceil(list.size()/8)+1);
            msgInfo.setMsg("查询成功");
            msgInfo.setData(list);
        }else{
            msgInfo.setCode(1);
            msgInfo.setMsg("无数据");
            msgInfo.setData(list);
        }
        return msgInfo;
    }


    /**
     * 概览
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value="view")
    public MsgInfo view(@RequestParam(value = "id") Integer id){
        MsgInfo msgInfo = new MsgInfo();
        PlantEncyclopedias byId = plantEncyclopediasService.findById(id);
        msgInfo.setData(byId);
        return msgInfo;
    }




}
